package com.example.springboot.modules.test.controller;

import com.example.springboot.modules.common.vo.Result;
import com.example.springboot.modules.test.entity.Student;
import com.example.springboot.modules.test.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 127.0.0.1/api/student ---post
     * {"studentName":"hj"}
     * {"studentName":"hj1","studentCard":{"cardNum":"202250111"}}
     */
    @PostMapping(value = "/student",consumes = "application/json")
    public Result<Student> insertStudent(@RequestBody Student student) {
        return studentService.insertStudent(student);
    }

    /**
     * 127.0.0.1/api/student ---put
     * {"id":1,"studentName":"hj"}
     */
    @PutMapping(value = "/student",consumes = "application/json")
    public Result<Student> updateStudent(@RequestBody Student student){
        return studentService.updateStudent(student);
    }

    /**
     *127.0.0.1/api/student/10  ---delete
     */
    @DeleteMapping(value = "/student/{id}")
    public Result<Object> deleteStudentById(@PathVariable int id){
        return studentService.deleteStudentById(id);
    }

    /**
     *127.0.0.1/api/student/1  ---get
     */
    @GetMapping(value = "/student/{id}")
    public Student getStudentById(@PathVariable int id){
        return studentService.getStudentById(id);
    }
}
